import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { getRangePickerDefaultProps } from '#/utils';

import { $t } from '#/locales';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'userId',
      label: $t('views.mall.trade.brokerage.withdraw.userId'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mall.trade.brokerage.withdraw.userIdPlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'type',
      label: $t('views.mall.trade.brokerage.withdraw.type'),
      component: 'Select',
      componentProps: {
        placeholder: $t('views.mall.trade.brokerage.withdraw.typePlaceholder'),
        allowClear: true,
        options: getDictOptions(DICT_TYPE.BROKERAGE_WITHDRAW_TYPE, 'number'),
      },
    },
    {
      fieldName: 'userAccount',
      label: $t('views.mall.trade.brokerage.withdraw.account'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mall.trade.brokerage.withdraw.accountPlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'userName',
      label: $t('views.mall.trade.brokerage.withdraw.username'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.mall.trade.brokerage.withdraw.usernamePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'bankName',
      label: $t('views.mall.trade.brokerage.withdraw.bankName'),
      component: 'Select',
      componentProps: {
        placeholder: $t('views.mall.trade.brokerage.withdraw.bankNamePlaceholder'),
        allowClear: true,
        options: getDictOptions(DICT_TYPE.BROKERAGE_BANK_NAME, 'string'),
      },
    },
    {
      fieldName: 'status',
      label: $t('common.status'),
      component: 'Select',
      componentProps: {
        placeholder: $t('common.statusPlaceholder'),
        allowClear: true,
        options: getDictOptions(DICT_TYPE.BROKERAGE_WITHDRAW_STATUS, 'number'),
      },
    },
    {
      fieldName: 'createTime',
      label: $t('views.mall.trade.brokerage.withdraw.createTime'),
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'id',
      title: $t('views.common.id'),
      minWidth: 80,
    },
    {
      field: 'userId',
      title: $t('views.mall.trade.brokerage.withdraw.userId'),
      minWidth: 80,
    },
    {
      field: 'userNickname',
      title: $t('views.mall.trade.brokerage.withdraw.nickname'),
      minWidth: 80,
    },
    {
      field: 'price',
      title: $t('views.mall.trade.brokerage.withdraw.price'),
      minWidth: 80,
      formatter: 'formatAmount2',
    },
    {
      field: 'feePrice',
      title: $t('views.mall.trade.brokerage.withdraw.feePrice'),
      minWidth: 80,
      formatter: 'formatAmount2',
    },
    {
      field: 'type',
      title: $t('views.mall.trade.brokerage.withdraw.type'),
      minWidth: 120,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.BROKERAGE_WITHDRAW_TYPE },
      },
    },
    {
      title: $t('views.mall.trade.brokerage.withdraw.withdrawInfo'),
      minWidth: 200,
      slots: { default: 'withdraw-info' },
    },
    {
      field: 'createTime',
      title: $t('views.mall.trade.brokerage.withdraw.createTime'),
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      field: 'remark',
      title: $t('common.remark'),
      minWidth: 120,
    },
    {
      title: $t('common.status'),
      minWidth: 200,
      slots: { default: 'status-info' },
    },
    {
      title: $t('common.action'),
      width: 150,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
